// src/main.ts
import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from './router'
import  "./style.css";
import store from './store'
import PanelHead from './components/PanelHead.vue'




const localData = localStorage.getItem('pz_v3pz')
if(localData){
  store.commit('dynamicMenu',JSON.parse(localData).menu.routerList)
  store.state.menu.routerList.forEach(item => {
    router.addRoute('main',item)
  });
}

router.beforeEach((to,from)=>{
  const token = localStorage.getItem('pz_token')
  if(!token && to.path !== '/login'){
    return '/login'
  }else if(token && to.path === '/login'){
    return '/'
  }else{
    return true
  }
})

// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import { el, fr } from 'element-plus/es/locales.mjs'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}


app.use(ElementPlus) // 全局注册所有组件
app.use(router) // 注册路由
app.use(store) // 注册状态管理
app.mount('#app')

app.component('PanelHead', PanelHead)

